/*
 * @Author: sunkai@xinxinapp.cn
 * @Date: 2021-06-24 10:38:41
 * @LastEditTime: 2021-06-24 10:48:28
 * @LastEditors: sunkai@xinxinapp.cn
 * @Description: 
 * @FilePath: /fed-e-task-05-01/code/01.js
 */
const fs = require('fs')

function geFileList(path) {
 const filesList = []
 readFile(path,filesList)
 let totalSize = 0
 for(let i=0; i < filesList.length; i++) {
  const item = filesList[i]
  totalSize += item.size
 }
 return totalSize
}
 
function readFile(path, filesList) {
 files = fs.readdirSync(path)
 files.forEach(walk)
 function walk(file) { 
  states = fs.statSync(path + '/' + file)
  if(states.isDirectory()) {
   readFile(path + '/' + file, filesList)
  } else { 
   const obj = {}
   obj.size = states.size
   obj.path = path +'/' + file
   filesList.push(obj)
  }  
 }
}

console.log(geFileList("./code"))
